home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
asm
/
amislib.exe
/
NOTE.ASM
< prev
next >
Wrap
Assembly Source File
|
1992-09-12
|
26KB
|
1,010 lines
;-----------------------------------------------------------------------
; NOTE.ASM Public Domain 1992 Ralf Brown
; You may do with this software whatever you want, but
; common courtesy dictates that you not remove my name
; from it.
;
; Popup to append one or more lines to a text file. Demonstration of the
; use of DOS from within an AMIS-compliant TSR.
; Note: popup may be done from the commandline or via a hotkey; however,
; the hotkey support requires a newer BIOS which has the INT 15/4F
; keyboard intercept
;
; Version 0.90
; LastEdit: 9/10/92
;-----------------------------------------------------------------------
__TINY__ equ 1 ; using Tiny model
INCLUDE AMIS.MAC
@Startup 3,00 ; need DOS 3.00
; this macro also takes care of declaring
; all the segments in the required order
;-----------------------------------------------------------------------
;
VERSION_NUM equ 005Ah ; v0.90
VERSION_STR equ "0.90"
; uncomment the following line to use the generic hotkey dispatcher, at a cost
; of an additional 80 bytes
;CUSTOM_HOTKEY_CODE equ 1
WINDOW_TOP equ 0 ; topmost row of TSR's popup window
WINDOW_LEFT equ 5 ; leftmost column of TSR's popup window
WINDOW_HEIGHT equ 3 ; height (including frame) of popup window
WINDOW_WIDTH equ 70 ; width (including frame) of popup window
LOCAL_STACK_SIZE equ 128 ; size of local stack in bytes
HOTKEY_SCAN equ SCAN_N ; scan code for 'N' key
HOTKEY_NAME equ "N"
LODSB_ES MACRO
DB 26h,0ACh ; LODSB ES:
ENDM
;-----------------------------------------------------------------------
; Put the resident code into its own segment so that all the offsets are
; proper for the new location after copying it into a UMB or down into
; the PSP.
;
TSRcode@
;-----------------------------------------------------------------------
; Since we need a PSP, but might be loaded into a UMB or at the top of
; conventional memory, we make a copy of the all-important first 64 bytes
; of the PSP here. After relocation, this copy will start at offset 0
;
TSR_PSP db 64 dup (?)
;-----------------------------------------------------------------------
; TSR's initialized data storage
;
TSRdata@
TSR_name db "NOTE",0 ; title for popup window
int13_25_busy label word ; allow both to be tested in one operation
int13_busy db 0
int25_busy db 0
int26_TSR_busy label word ; allow both to be tested in one operation
int26_busy db 0
TSR_activated db 0
want_popup db 0
want_shutdown db 0
popup_INT28 db 0
;;; add TSR-specific initialized data below
CRLF_buffer db 13,10
TSRdataEnd@
;-----------------------------------------------------------------------
; TSR's uninitialized data storage
;
TSRbss@
INDOS_ptr dd ?
CRITERR_ptr dd ?
interrupted_DTA dd ?
interrupted_PSP dw ?
interrupted_SP dw ?
interrupted_SS dw ?
interrupted_cursorpos dw ?
display_page_attr label word
display_attr db ?
display_page db ?
screen_width db ?
cursor_pos label word
cursor_x db ?
cursor_y db ?
screen_buffer db (WINDOW_HEIGHT*WINDOW_WIDTH*2) dup (?)
local_stack db LOCAL_STACK_SIZE dup (?)
local_stack_bottom label byte
;;; add TSR-specific uninitialized data below
notefile_handle dw ?
edit_buffer db WINDOW_WIDTH-2 dup (?)
TSRbssEnd@
;-----------------------------------------------------------------------
TSR_main proc near
ASSUME DS:TGROUP,ES:NOTHING
xor si,si ; SI stores line length
TSR_main_loop:
mov dx,256*(WINDOW_TOP+1) + (WINDOW_LEFT+1)
add dx,si
call TSR_move_cursor
call TSR_getkey
cmp al,0Dh ; Enter pressed?
je TSR_main_line_end
cmp al,27 ; Esc pressed?
je TSR_main_done
cmp al,8
je backspace
cmp al,0 ; extended ASCII?
je TSR_main_loop ; if yes, ignore
cmp al,0E0h
jne got_char
cmp ah,0
jne TSR_main_loop
got_char:
cmp si,WINDOW_WIDTH-2
jb store_char
beep:
mov ax,0E07h ; beep
int 10h
jmp TSR_main_loop
store_char:
mov edit_buffer[si],al
inc si ; remember that we got another char
call TSR_put_char
jmp TSR_main_loop
backspace:
or si,si
jz beep
dec si
mov dx,256*(WINDOW_TOP+1) + (WINDOW_LEFT+1)
add dx,si
call TSR_move_cursor
mov al,' '
call TSR_put_char
jmp TSR_main_loop
TSR_main_line_end:
mov ah,40h
mov bx,notefile_handle
mov cx,si
mov dx,offset TGROUP:edit_buffer
int 21h
mov ah,40h
mov cx,2
mov dx,offset TGROUP:CRLF_buffer
int 21h
call TSR_clear_window
jmp TSR_main ; restart for next line
TSR_main_done:
mov bx,notefile_handle
mov ah,45h ; DUP handle
int 21h
jc TSR_main_exit ; quit now if unable to duplicate
mov bx,ax
mov ah,3Eh ; close duplicate
int 21h
TSR_main_exit:
ret
TSR_main endp
;-----------------------------------------------------------------------
; Function that performs any necessary cleanup prior to the TSR being
; removed from memory. At the time it is called, the TSR is effectively
; popped up, though it has not modified the screen. If this routine needs
; to write on the screen, it must save and restore the screen contents
; itself
;
TSR_shutdown proc near
mov bx,notefile_handle
mov ah,3Eh ; close the file
int 21h
ret
TSR_shutdown endp
;-----------------------------------------------------------------------
TSR_INT24_handler:
mov al,03h ; FAIL, for now
; iret ; save a byte by falling through to next handler
;-----------------------------------------------------------------------
; Simply ignore Ctrl-Break and Ctrl-C interrupts
;
TSR_INT1B_handler:
TSR_INT23_handler:
iret
;=======================================================================
; It should not be necessary to make any changes between here and the
; end of the resident portion (other than the TSR identifier in the ALTMPX
; macro) in order to modify this code for a different purpose.
;=======================================================================
;-----------------------------------------------------------------------
;
TSR_getkey proc near
mov ah,11h ; keystroke available?
int 16h
jnz TSR_getkey_got_one ; if yes, get it, otherwise
int 28h ; give other TSRs a chance to do work
jmp TSR_getkey
TSR_getkey_got_one:
mov ah,10h ; get the keystroke
int 16h
ret
TSR_getkey endp
;-----------------------------------------------------------------------
; entry: DH = row, DL = column
;
TSR_move_cursor proc near
ASSUME DS:TGROUP,ES:NOTHING
mov cursor_pos,dx
mov bh,display_page
mov ah,2 ; BIOS move-cursor function
int 10h
ret
TSR_move_cursor endp
;-----------------------------------------------------------------------
; exit: AX,BX,CX,DX destroyed
;
TSR_put_char_186 proc near
mov al,186
;; fall through to TSR_put_char
TSR_put_char_186 endp
;-----------------------------------------------------------------------
; entry: AL = char
; exit: AH,BX,CX,DX destroyed
;
TSR_put_char proc near
mov cx,1
;; fall through to TSR_put_line
TSR_put_char endp
;-----------------------------------------------------------------------
; entry: AL = char, CX = repeat count
; exit: AX,BX,CX,DX destroyed
;
TSR_put_line proc near
ASSUME DS:TGROUP,ES:NOTHING
add cursor_x,cl
mov bx,display_page_attr
mov ah,9
int 10h
mov al,cursor_x
cmp al,screen_width
jb TSR_put_line_done
mov cursor_x,0
inc cursor_y
;
; need to handle case of falling off the bottom
;
TSR_put_line_done:
mov dx,cursor_pos
mov ah,2 ; set cursor position
int 10h
ret
TSR_put_line endp
;-----------------------------------------------------------------------
save_screen proc near
ASSUME DS:TGROUP,ES:NOTHING
mov ah,0Fh
int 10h ; get video mode and active page
mov display_page,bh
mov screen_width,ah
mov ah,3 ; get cursor position on page BH
int 10h
mov interrupted_cursorpos,dx
push ds
pop es
ASSUME ES:TGROUP
mov di,offset TGROUP:screen_buffer
mov dh,WINDOW_TOP
save_screen_loop1:
mov dl,WINDOW_LEFT
save_screen_loop2:
mov ah,2 ; set cursor position on page BH
int 10h
mov ah,8 ; read character&attribute on page BH
int 10h
stosw ; and remember